The most accurate models in this course are the least interpretable. A Random Forest of five hundred trees or a neural network with thousands of weights makes decisions no human can trace — which becomes unacceptable the moment those decisions affect loan approvals, medical diagnoses or hiring. Explainable ML is the set of techniques for recovering an account of why a black-box model predicted what it did.
We first separate interpretable models, which are transparent by construction, from explainable ones, which require a post-hoc method — and look at real cases, including the Amazon hiring algorithm, where the absence of explanation allowed bias to go undetected. The main technique is the surrogate model: fit something simple to imitate the black box, then read the simple model instead. Global surrogates approximate the whole decision surface; LIME builds a local surrogate around one specific prediction by perturbing the input and weighting by proximity. Throughout, fidelity is the question that matters: how faithfully does the explanation reproduce the model it claims to explain?
The need for interpretability arises from an incompleteness in problem formalization. For many real-world tasks, getting the prediction (the what) is not enough; we must also explain how the model arrived at that prediction (the why).
Machine learning models can pick up biases from training data, effectively turning them into discriminatory systems. Interpretability serves as a crucial debugging tool for detecting such bias.
While often used interchangeably, a useful distinction exists:
| Aspect | Interpretable ML | Explainable ML |
|---|---|---|
| Definition | Models transparent by design | Techniques explaining any model, including black boxes |
| Analogy | Glass box — you can see through it | Black box needing X-ray vision |
| Examples | Linear Regression, Decision Trees | LIME, SHAP for Neural Networks |
| Approach | Examine model structure itself | Use separate explanation methods |
Figure: Spectrum of model interpretability from transparent to black-box models.
Explainability methods are usually grouped by the scope of what they explain. The distinction matters because the two kinds answer different questions and are evaluated differently.
Explain the overall behavior of the model across the entire dataset.
Explain individual predictions for specific instances.
A global surrogate model is an interpretable model trained to approximate the predictions of a black-box model. We can draw conclusions about the black-box by interpreting the surrogate.
Steps to Obtain a Global Surrogate:
An explanation is itself a model, so it needs to be evaluated rather than trusted. The following properties are the ones normally checked:
| Property | Definition | Measurement |
|---|---|---|
| Fidelity | How well does the explanation match the black box? | R² score (regression), Agreement Rate (classification) |
| Accuracy | How correct are the explanations vs. ground truth? | Percentage correct on unseen data |
| Stability | Do similar inputs get similar explanations? | Variance of explanations for perturbed inputs |
| Consistency | Do different models give similar explanations? | Correlation between explanations |
R² is a robust measure for evaluating how well a surrogate model replicates a black-box model, especially for regression or when comparing predicted probabilities in classification.
Where:
R² is continuous, so we need some idea of what counts as an acceptable value. The following ranges are used as rough guidance:
| R² (Fidelity) | Interpretation | Use Case |
|---|---|---|
| R² > 0.9 | Excellent fidelity | Safe for critical decisions |
| 0.7 < R² ≤ 0.9 | Good fidelity | Acceptable for most use cases |
| 0.5 < R² ≤ 0.7 | Moderate fidelity | Use with caution, validate carefully |
| R² ≤ 0.5 | Poor fidelity | Explanation unreliable, do not use |
Using the Adult dataset with a Random Forest black-box model:
Lasso (L1 regularization) is ideal for creating sparse, interpretable surrogate models. By tuning the regularization parameter $\lambda$ (alpha), we control the number of features:
| Regularization Strength | Features Selected | Trade-off |
|---|---|---|
| High λ | Few (e.g., K=1) | Most interpretable, lowest fidelity |
| Medium λ | Moderate (e.g., K=5-10) | Good balance (recommended) |
| Low λ | All (e.g., K=50) | Highest fidelity, hard to interpret |
Using Gradient Boosting as black-box and comparing Lasso vs. Regression Tree surrogates:
| Surrogate | Train Fidelity R² | Test Fidelity R² | Test Accuracy R² | Features Used |
|---|---|---|---|---|
| Lasso (α=18.4) | 0.950 | 0.947 | 0.883 | 24 |
| Regression Tree (depth=3) | 0.900 | 0.909 | 0.840 | 4 |
LIME (Local Interpretable Model-agnostic Explanations) explains individual predictions by approximating the black-box model locally around a specific instance using an interpretable model.
Figure: LIME generates perturbed samples around instance X, weights them by proximity, and fits a local linear model (dashed line) to approximate the complex decision boundary.
The procedure below turns the idea of a local approximation into a concrete algorithm. Steps 2 and 3 are what make the surrogate local rather than global:
Because LIME depends on random perturbation and on a choice of neighborhood, its explanations are not guaranteed to be stable. The main limitations are worth knowing before relying on it:
Two related properties are often confused, and the distinction matters when reporting explanation quality:
| Property | Definition | Comparison |
|---|---|---|
| Consistency | How much explanations differ between models trained on the same task with similar predictions | Between models (e.g., XGBoost vs. Neural Network) |
| Stability | How much explanations vary for similar instances in a fixed model | Between similar instances for one model |
Enter black-box and surrogate predictions to compute fidelity metrics:
Scenario: Credit approval system with 5 test cases.
| Case | Black Box Prediction (Prob) | Surrogate Prediction (Prob) |
|---|---|---|
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 |
Click on each model type to see its interpretability characteristics:
Simulate how LIME generates perturbed samples around an instance:
Original Instance: Debt Ratio = 0.30, Income = $50K
Black Box Prediction: 0.65 (65% approval probability)
| Sample | Debt Ratio | Income ($K) | Distance from X | Weight |
|---|---|---|---|---|
| 1 | 0.29 | 51 | 0.014 | 0.99 |
| 2 | 0.31 | 49 | 0.014 | 0.99 |
| 3 | 0.35 | 45 | 0.071 | 0.86 |
| 4 | 0.50 | 30 | 0.283 | 0.24 |
Closer samples receive higher weights, ensuring the local model focuses on the neighborhood of X.
Adjust the regularization strength to see the trade-off between features and fidelity:
Medium (α=10)Figure: Global surrogates provide a single interpretable model for all predictions, while LIME generates a custom local explanation for each individual instance.
Scenario: A credit approval black-box model and its decision tree surrogate are tested on 1000 cases.
| Model/Method | Correct Predictions (vs Ground Truth) | Match with Black Box |
|---|---|---|
| Black Box Model | 900/1000 = 90% Accuracy | — |
| Explanation (Surrogate) Model | 850/1000 = 85% Accuracy | 950/1000 = 95% Fidelity |
Accuracy (85%): The surrogate is correct about the actual outcome 850 out of 1000 times.
Fidelity (95%): The surrogate agrees with the black box 950 out of 1000 times.
The 10% gap between fidelity and accuracy reveals two types of errors:
High fidelity (95%) means the surrogate is a trustworthy approximation of the black box. However, since the black box itself has 90% accuracy, the surrogate's 85% accuracy shows that simplifying the model introduces some additional error. This is the typical interpretability-accuracy trade-off.
Given: Black box predictions: [0.8, 0.3, 0.9, 0.2, 0.7] and Surrogate predictions: [0.75, 0.35, 0.85, 0.25, 0.72]. Compute the R² fidelity score.
Result: R² ≈ 0.97, indicating excellent fidelity (well above the 0.9 threshold).
Scenario: Loan prediction for an applicant with 30% debt ratio and $50K income. Black box predicts 0.65 approval probability. LIME generates 1000 perturbed samples.
| Sample | Debt Ratio | Income ($K) | Black Box Pred | LIME Pred | Error |
|---|---|---|---|---|---|
| 1 | 0.29 | 51 | 0.67 | 0.66 | 0.01 |
| 2 | 0.31 | 49 | 0.63 | 0.64 | 0.01 |
| ... | ... | ... | ... | ... | ... |
| 1000 | 0.32 | 48 | 0.61 | 0.62 | 0.01 |
Given: Weighted SSE = 0.052, Weighted SST = 0.433. Compute local fidelity R².
R² = 0.88 indicates good local fidelity. The linear approximation is trustworthy in the neighborhood of this instance. However, this explanation should not be generalized beyond similar applicants.
A Gradient Boosting model predicts car prices. You fit Lasso surrogates with different α values:
| Alpha (α) | Features Selected | Fidelity R² | Actual R² |
|---|---|---|---|
| 0.1 | 58 | 0.943 | 0.882 |
| 1.0 | 42 | 0.940 | 0.884 |
| 10.0 | 31 | 0.946 | 0.887 |
| 100.0 | 14 | 0.905 | 0.844 |
| 1000.0 | 5 | 0.800 | 0.750 |
Question: Which α provides the best balance? Justify your answer.
α = 100.0 or an intermediate value around α = 50-100 provides the best balance. With 10-15 features, the model remains interpretable while maintaining fidelity above the 0.9 threshold. The actual R² of 0.844 is acceptable for most business applications.
A medical diagnosis black-box model achieves 88% accuracy on 500 test cases. A decision tree surrogate achieves 82% accuracy and 94% fidelity. How many cases show:
Solution:
Let $x$ = both correct, $y$ = both wrong, $z$ = BB correct but surrogate wrong, $w$ = surrogate correct but BB wrong.
We know: $x + y = 470$ (fidelity), $x + z = 440$ (BB correct), $x + w = 410$ (surrogate correct), and $x + y + z + w = 500$.
Solving: $z + w = 30$. From $x + z = 440$ and $x + w = 410$, we get $z - w = 30$. Thus $z = 30, w = 0$.
Then $x = 410$ and $y = 60$.
A deep learning model for pneumonia detection achieves 96% accuracy on chest X-rays. An interpretability analysis reveals the model focuses primarily on hospital wristband tags in the image corners rather than lung patterns. Answer the following:
Solution:
You have a random forest with 200 trees predicting house prices using 50 features. You want to build a global surrogate. Which model would you choose and what are the trade-offs of:
Solution:
Given three perturbed samples around instance X with their black-box predictions and proximity weights:
| Sample | Feature 1 | Feature 2 | BB Pred | Weight |
|---|---|---|---|---|
| A | 2 | 5 | 0.8 | 0.9 |
| B | 3 | 4 | 0.6 | 0.7 |
| C | 1 | 6 | 0.9 | 0.5 |
A local linear surrogate predicts: ŷ = 0.2 + 0.1·x₁ + 0.05·x₂. Compute the weighted SSE and comment on whether this is a good local fit.
Step 1: Compute surrogate predictions:
Step 2: Compute weighted SSE:
Step 3: Compute weighted SST (mean BB pred = 0.767):
Step 4: R² = 1 - (0.07225/0.0294) = -1.46
Conclusion: Negative R²! The local surrogate is worse than simply predicting the mean. This indicates the linear model is inappropriate for this local region, or the perturbation neighborhood is too large.
You need to explain a complex Gradient Boosting classifier to:
Which explainability method(s) would you use for each stakeholder, and why?
1. Regulator (Global Understanding):
2. Customer (Local Explanation):
You train an XGBoost model and a Neural Network on the same classification task. Both achieve ~87% accuracy. For a test instance, LIME on XGBoost identifies "credit_score" as the top feature with weight +0.15, while LIME on the Neural Network identifies "income" as top with weight +0.18 for the same instance. What does this suggest about consistency, and what should you do?
Analysis:
Actions:
Answer all 10 questions. Click an option for instant feedback.
Your score: 0 / 10